Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Why console.log(10 < 14 < 50) is true but console.log(10 > 7 > 2) is false?

Why console.log(10 < 14 < 50) is true but console.log(10 > 7 > 2) is false? why does first give true and second gives false

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It works that way:

First it calculate the left side (10 < 14) => it returns True, which is also 1.

Then it calculates the right side: (True < 50) which is (1 < 50) and this is also True.

On the other side, (10 > 7) => True = 1, but (True > 2) which is (1 > 2) is False.

If you'll try: console.log(10 < 14 == 1) you will see that it's also True.

about 4 years ago · Juan Pablo Isaza Relatório

0

This is not how you would check an interval in JS.

Your code would be interpreted from left to right according to operator precedence. The comparison operators are binary operators, they take a left-hand expression and a right-hand expression

10 < 15 < 50
// To
true < 50 
// To
1 < 50

// And 
10 > 7 > 2
// To
true > 2 
// To
1 > 2

You should do:

console.log(14 < 10 && 14 <50)
//
console.log(7 < 10 && 7 > 2)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda